package com.bwie.controller;

import com.bwie.pojo.TbProd;
import com.bwie.pojo.TbType;
import com.bwie.service.IUserService;
import com.bwie.service.TbProdService;
import com.bwie.utils.R;
import com.bwie.vo.PageInfoVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletResponse;
import java.util.ArrayList;
import java.util.List;

/**
 * description:
 *
 * @Author caoshuaifeng
 * @Create 2025/3/3 9:41
 * @Version 1.0
 */
@RestController
@RequestMapping("/prod/index")
public class IndexController {

    @Autowired
    TbProdService tbProdService;
    @Autowired
    IUserService iUserService;

    @PostMapping("/getProdList")
    public R getProdList(@RequestBody PageInfoVo pageInfoVo){
        return tbProdService.getProdList(pageInfoVo);
    }

    @PostMapping("/getUserById1/{userId}")
    public R getUserById1(@PathVariable("userId") Integer userId){
      return   iUserService.getUserById(userId);

    }

    @PostMapping("/addProd")
    public R addProd(@RequestBody TbProd tbProd){
        return tbProdService.addProd(tbProd);
    }

    @PostMapping("/uploadFile")
    // 处理POST请求，上传文件
    public R uploadFile(@RequestPart("file") MultipartFile file){
        // 接收文件参数
        return tbProdService.uploadFile(file);

    }

    /**
     * 根据Id查询商品
     * @param prodId
     * @return
     */
    @PostMapping("/getProdById/{prodId}")
    public R getProdById(@PathVariable("prodId") Integer prodId){
        return tbProdService.getProdById(prodId);
    }
    /**
     * 根据Id修改商品
     * @param tbProd
     * @return
     */
    @PostMapping("/updateProd")
    public R updateProd(@RequestBody TbProd tbProd){
    return tbProdService.updateProd(tbProd);

    }
    /**
     * 根据Id删除1商品
     */
    @PostMapping("/deleteProdById/{prodId}")
    public R deleteProdById(@PathVariable("prodId") Integer prodId){
        return tbProdService.deleteProdById(prodId);
    }

    @PostMapping("/deleteAll")
    public R deleteAll(@RequestBody ArrayList<TbProd> tbProds){
        return tbProdService.deleteAll(tbProds);

    }

    @PostMapping("/getTypeList")
    public R getTypeList(){
        return tbProdService.getTypeList();

    }

    @GetMapping("/exportExcel")
    public void exportExcel(HttpServletResponse response) throws Exception {
        tbProdService.exportExcel(response);

    }
    @PostMapping("/importExcel")
    public R importExcel(@RequestPart MultipartFile file){
        return tbProdService.importExcel(file);

    }




}
